﻿// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
	using System.Diagnostics;
	using System.Drawing;
	using System.Drawing.Drawing2D;
	using System.Reflection;
	using System.Windows.Forms;

	using CE.Classes;
	using CE.CustomControls;

	public struct CopyDataStruct
	{
		#region Fields

        private int _cbData;
        private int _dwData;
        private string _lpData;

        #endregion

        #region Properties

        public int CbData
        {
            get { return _cbData; }
            set { _cbData = value; }
        }

        public int DwData
        {
            get { return _dwData; }
            set { _dwData = value; }
        }
        

        public string LpData
        {
            get { return _lpData; }
            set { _lpData = value; }
        }

        #endregion

		#region Constructors

		public CopyDataStruct(string data)
		{
			_lpData = data + "\0";
			_cbData = data.Length;
			_dwData = 0;
		}

		#endregion Constructors

        #region Methods

        public static bool operator ==(CopyDataStruct x, CopyDataStruct y)
		{
            return (x._cbData == y._cbData && x._dwData == y._dwData && x._lpData == y._lpData);
		}

		public static bool operator !=(CopyDataStruct x, CopyDataStruct y)
		{
            return !(x == y);
        }

        #endregion
    }

	static class Program
	{
		#region Fields

		public static Color AutoHideStripTabEndColor = Color.FromArgb(242, 242, 242);
		public static Color AutoHideStripTabStartColor = Color.FromArgb(207, 207, 207);
		public static ProfessionalColorTable ColorTable = new ProfessionalColorTable();
		public static Color DefaultEndColor = Color.FromArgb(244, 247, 252);
		public static Color DefaultStartColor = Color.FromArgb(233, 236, 250);
		public static Color DockPaneStripActiveTabEndColor = Color.FromArgb(210, 230, 250);
		public static Color DockPaneStripActiveTabStartColor = Color.FromArgb(252, 253, 254);
		public static Color DockPaneStripInActiveTabEndColor = Color.FromArgb(152, 180, 210);
		public static Color DockPaneStripInActiveTabStartColor = Color.FromArgb(236, 245, 252);
		public static Color DockPanelEndColor = Color.FromArgb(100, 100, 100);
		public static Color DockPanelStartColor = Color.FromArgb(127, 127, 127);
		public static Color DockStripEndColor = DefaultEndColor;
		public static Color DockStripStartColor = Color.FromArgb(236, 239, 250);
		public static CustomRenderer Renderer = new CustomRenderer();

		private static Color _ImgMarginColor1 = Color.FromArgb(243, 246, 251);
		private static Color _ImgMarginColor2 = Color.FromArgb(213, 218, 232);
		private static Color _ItemColor1 = Color.FromArgb(239, 247, 250);
		private static Color _ItemColor2 = Color.FromArgb(186, 228, 246);
		private static Color _ItemOutlineColor = Color.FromArgb(150, 217, 249);
        private static Color _bgEndColor = ColorTranslator.FromHtml("#d7e2e8");//Color.FromArgb(125, 208, 255);//Color.FromArgb(98, 150, 217);
        private static Color _bgStartColor = ColorTranslator.FromHtml("#e9f7ff");//Color.FromArgb(223, 237, 253);

		#endregion Fields

		#region Methods

		public static void FeatureRequest()
		{
			Process.Start(Constants.RequestFeatureLink);
		}

		private static Rectangle GetRectangle(Control control)
		{
			return new Rectangle(0, 0, control.Width, control.Height);
		}

		public static void MakeBackgroundGradient(System.Drawing.Graphics graphics,
            Control control)
		{
			MakeBackgroundGradient(graphics, control, GetRectangle(control), _bgStartColor, _bgEndColor);
		}

		public static void MakeBackgroundGradient(System.Drawing.Graphics graphics, Control control,
		    Rectangle area, System.Drawing.Color startColor, System.Drawing.Color endColor)
		{
			if (control == null) return;

			LinearGradientBrush brush = new LinearGradientBrush(area,
			    startColor, endColor, LinearGradientMode.Vertical);
			graphics.FillRectangle(brush, area);
		}

		public static void ReportBugs()
		{
			Process.Start(Constants.ReportBugLink);
		}

		public static void ShowError(string text)
		{
			MessageBox.Show(text, Constants.ProgramName, MessageBoxButtons.OK,
                MessageBoxIcon.Error);
		}

		public static void ShowMessage(string text)
		{
			MessageBox.Show(text, Constants.ProgramName, MessageBoxButtons.OK,
			                MessageBoxIcon.Information);
		}

		public static DialogResult ShowQuestion(string text)
		{
			DialogResult result = MessageBox.Show(text, Constants.ProgramName,
			                                      MessageBoxButtons.YesNo,
			                                      MessageBoxIcon.Question);
			return result;
		}

		[STAThread]
		static void Main(string[] args)
		{
			Application.SetCompatibleTextRenderingDefault(false);
            System.Xml.XmlDocument settingsDoc = new System.Xml.XmlDocument();
            settingsDoc.Load(Constants.ConfigFile);
            System.Xml.XmlNodeList nodeList = settingsDoc.GetElementsByTagName("Application")[0].ChildNodes;
            bool enableSplash = Convert.ToBoolean(nodeList[9].InnerText);
			if (enableSplash) {
                CE.Splash.Splasher.Show(typeof(CE.Splash.SplashForm),
                    Assembly.GetExecutingAssembly().GetName().Version.ToString());
            }
			Application.EnableVisualStyles();
            bool enableThemes = Convert.ToBoolean(nodeList[10].InnerText);
			if (enableThemes) {
                ToolStripManager.Renderer = new Office2007Renderer();
            }

			using (MainForm mainForm = new MainForm(args))
			      {
				      Application.Run(mainForm);
			      }
		}

		#endregion Methods
	}
}